*Structural-Analysis04.do
****************************************************************************************
**************************Analysis for 1999*********************************************
****************************************************************************************
 clear matrix

*
*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace
clear
set mem 300000
set matsize 800

set more off

*****************This Do-File Runs The Heckman Two-Step Selection Model*****************
*****************Note: Heckman Procedure Uses Reduced-Form Probit***********************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\Selection-Probit_04_df.do"

*****************This Files Run the CTaCS Program***************************************
*****************Note: WS = Wage/Salary SE = Self-Employment Real = Sample *************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsWS04.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSE04.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsReal04.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSED04.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSEH04.do"


***************************Merge CTaCS Output to Master Data****************************


use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-04ws.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxWS 
rename totprovtax totprovtaxWS 
rename tottax tottaxWS

keep pucpid26 totfedtaxWS totprovtaxWS tottaxWS

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsWS.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-04se.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSE 
rename totprovtax totprovtaxSE 
rename tottax tottaxSE

keep pucpid26 totfedtaxSE totprovtaxSE tottaxSE

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsSE.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-04real.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxReal 
rename totprovtax totprovtaxReal
rename tottax tottaxReal

keep pucpid26 totfedtaxReal totprovtaxReal tottaxReal

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsReal", replace

**********
use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-04SED.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSED 
rename totprovtax totprovtaxSED 
rename tottax tottaxSED

keep pucpid26 totfedtaxSED totprovtaxSED tottaxSED

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsSED.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-04SEH.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSEH 
rename totprovtax totprovtaxSEH 
rename tottax tottaxSEH

keep pucpid26 totfedtaxSEH totprovtaxSEH tottaxSEH

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsSEH.dta", replace
***********************
use "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04analysis", clear

sort pucpid26
*drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsWS"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsSE"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsReal"
tab _merge
drop _merge
**********
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsSED"
tab _merge
drop _merge
*
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04ctacsSEH"
tab _merge
drop _merge
**************

*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace

**************Summarize Predicted Earnings and Predicted Taxes**********************

sum  btearningSE btearningE 
bysort selfemp:  sum earng42

sum  tottaxWS tottaxSE tottaxReal
bysort selfemp: sum inctx27 
sum inctx27 

sum  tottaxWS tottaxSE tottaxReal if inva27==0 & male==1
bysort selfemp: sum inctx27 if inva27==0 & male==1
sum inctx27 if inva27==0 & male==1


*
gen taxdif=  ln((tottaxSE )/(tottaxWS))
gen taxdifDH=1  
gen Tax_ratio = (tottaxSE/(btearningSE+other-tottaxSE))
gen taxU=(tottaxSED)/(tottaxSE)
gen taxdifU=  ln(taxU)* Tax_ratio
gen taxdifU2 = (taxU-1)*Tax_ratio

replace tottaxSEH=1 if tottaxSEH==0
gen taxD = (tottaxSEH)/(tottaxSE)
*gen taxD = (tottaxSE)/(tottaxSEH)
gen taxdifD = ln(taxD)*Tax_ratio
gen taxdifD2 = (taxD-1)*Tax_ratio


sum  tottaxSED tottaxSEH tottaxSE if tottaxSEH>0 & tottaxSE>0
drop if tottaxSEH<=0 | tottaxSE<=0  
sum  tottaxSED tottaxSEH tottaxSE  


* Keeping only variables to be used in final   model
keep date  other other2 rse taxdifU taxdifD taxdifU2 taxdifD2 DhhE  inctx42 fditx42 pvitx42 inctx27 wkrcp42 spoucearn btearningE btearningSE  incomedif  year pucpid26 puchid25 selfemp inva27 inva42 capgn27   yrschl18 ecage26 age2 wksuem28 health male married   kids immigrant blucol   service newfoundland pei novascotia newbrunswick ontario quebec manitoba saskatchewan alberta bc earng42  wksuem28 udpd42 medx42 rppc42 rspwi42 pen42 oasgi42 cpqpp42 uiben42 capgn27 capgn42 sapis42 ottxm42 cpqpp42 alimo42 rppc42 chfed42 ccar42 alip42 year  kidage1-kidage7 rd yrxfte11  pctincearn whtcol incomedif  taxdif taxdifDH totfedtaxWS totprovtaxWS tottaxWS totfedtaxSE totprovtaxSE tottaxSE totfedtaxReal totprovtaxReal tottaxReal    
 
*SEstdf
*yrxfte11
 
 

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\04analysis", replace

 




  

